package com.dawn.kingbase.controller.user;

import com.dawn.kingbase.controller.BaseController;
import com.dawn.kingbase.model.page.PageWrap;
import com.dawn.kingbase.model.response.ApiResponse;
import com.dawn.kingbase.model.user.SysUser;
import com.dawn.kingbase.service.user.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author dongxiaoqi
 * @since 2022/12/19 16:33
 */
@Api(tags = "用户信息")
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

    @Autowired
    private UserService userService;

    @ApiOperation("新建")
    @PostMapping("/")
    public ApiResponse create(@RequestBody SysUser user) {
        return userService.create(user);
    }

    @ApiOperation("根据ID删除")
    @DeleteMapping("/{id}")
    public ApiResponse deleteById(@PathVariable String id) {
        return ApiResponse.success(userService.deleteById(id));
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/batch")
    public ApiResponse deleteByIdInBatch(@RequestParam String ids) {
        return ApiResponse.success(userService.deleteByIdInBatch(this.getIdList(ids)));
    }

    @ApiOperation("根据ID修改")
    @PutMapping("/")
    public ApiResponse updateById(@RequestBody SysUser user) {
        return ApiResponse.success(userService.updateUserById(user));
    }

    @ApiOperation("根据ID查询(MP方式)")
    @GetMapping("/{id}")
    public ApiResponse findById(@PathVariable String id) {
        return userService.findById(id);
    }


    @ApiOperation("根据ID查询(mybatis sql)")
    @GetMapping("/findUserById/{id}")
    public ApiResponse findUserById(@PathVariable String id) {
        return userService.findUserById(id);
    }

    @ApiOperation("分页查询")
    @PostMapping("/page")
    public ApiResponse findPage(@RequestBody PageWrap<SysUser> pageWrap) {
        return ApiResponse.success(userService.findPage(pageWrap));
    }

}
